package com.hlingsoft.cms.action;

import com.hlingsoft.cms.dao.*;
import com.hlingsoft.cms.entity.*;
import com.hlingsoft.cms.util.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by selbylei on 2015/5/30.
 */
@Controller
@RequestMapping("share")
public class ShareAction extends BaseAction {

    @Autowired
    private NewsDao newsDao;

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private AppUserDao appUserDao;

    @Autowired
    private ImageDao imageDao;

    @Autowired
    private LikesDao likesDao;

    /**
     * 分享h5界面
     * @param newsId
     * @param request
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "/news.htm")
         public String moment(
            @RequestParam(value = "newsId") long newsId,
            HttpServletRequest request, ModelMap modelMap) {
        News news = newsDao.getNewsById(newsId);
        if (news!=null){
            List<Comment> commentList=commentDao.getCommentByNewsId(newsId);
            AppUser appUser = appUserDao.getUserById(news.getAppUserId());
            List<Image> imageList = imageDao.getImageByNewsId(newsId);
            List<Likes> likesList = likesDao.getLikesByNewsId2(newsId);
            List<String> headImageList= new ArrayList<String>();
            for (Likes likes:likesList){
                AppUser likeUsers=appUserDao.getUserById(likes.getMyId());
                headImageList.add(likeUsers.getHeadImage());
            }

            modelMap.put("headImageList",headImageList);
            modelMap.put("likesCount",headImageList.size());
            modelMap.put("appUser",appUser);
            modelMap.put("news",news);
            modelMap.put("imageList",imageList);   //活动图片
            modelMap.put("commentList",commentList);
            return "manage/share/news";
        }else {
            return "此动态已被删除";
        }

    }


    /**
     * 好友邀请h5地址
     * @param request
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "/invite.htm")
    public String moment(
            HttpServletRequest request, ModelMap modelMap) {
        return "manage/share/invite";
    }





}
